<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
/*
	选择员工
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'one';
$return=array();
	//员工列表
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$return['params']=$params=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid']);
	$fields=array('name');
	if($_RQ['find']){
			$params2=array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid']);
			$params2['name like']='%'.trim($_RQ['find']).'%';
			$workerids=pdo_getall('jy_scrm_worker',$params2,array('id'),'id');
			if($workerids){
				$workerids=array_keys($workerids);
			}else{
				$workerids=-1;
			}
			$params['workerid']=$workerids;
			$return['params']['find']=$_RQ['find'];
	}
	$list=pdo_getslice('jy_worker_ewm_worker',$params,array($pindex,$psize),$total,$search_fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['name']=pdo_getcolumn('jy_scrm_worker',array('id'=>$item['workerid'],'uniacid'=>$_SESSION['uniacid']),'name');
			$item['avatar']=pdo_getcolumn('jy_scrm_worker',array('id'=>$item['workerid'],'uniacid'=>$_SESSION['uniacid']),'avatar');
			//整理返回数据
			if($_RQ['op']=='many'){
				$item['res']=array('id'=>$item['id'],'mid'=>$_RQ['ismid']?$item['mid']:$item['id'],'title'=>$item['name'],'image'=>$item['avatar']);
			}else{
				$item['res']=$_RQ['ismid']?$item['mid']:$item['id'];
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['htmls']=array(
		'type'=>'list',
		'list'=>array('data'=>'list','tip'=>'[如果员工还未同步系统MID，MID就是0]；同步系统MID的方法：只需员工企业微信访问一下，员工页面即可！','del_one'=>false,'delall'=>false,'edit'=>false,'list'=>array(
		    array('name'=>'id','title'=>'员工id','type'=>'string'),
			array('name'=>'name','title'=>'名称','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'res','title_field'=>'alias','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'find','select_name'=>'field','select_title'=>'筛选','is_radio'=>true,'options'=>'fields'),
	);
	$return['fields']=array(
		'name'=>'员工账号',
	);
	exi($return);
